//
//  LXAddClientViewController.m
//  跑跑快销
//
//  Created by linxian on 14-5-7.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "LXAddClientViewController.h"

@interface LXAddClientViewController ()

@end

@implementation LXAddClientViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    LXAddClientView *addClientView = [[LXAddClientView alloc] init];
    self.view = addClientView;
    _addClientView = addClientView;
    
    [self initArray];
    [self initUpView];
    
    self.navigationController.navigationBar.translucent = NO;
}

- (void)initArray
{
    NSArray * titleArray = [NSArray arrayWithObjects:@"名称:",@"类型:",@"地址:",@"电话:", nil];
    _titleArray = titleArray;
    NSArray *iArray = [NSArray arrayWithObjects:@"wrong.png",@"wrong.png",@"wrong.png",@"wrong.png",@"wrong.png",@"wrong.png",@"wrong.png",nil];
    _iArray = iArray;
    NSArray *industryArray = [NSArray arrayWithObjects:@"商场",@"百货",@"超市",@"便利店",@"餐饮",@"五金",@"其他",nil];
    _industryArray = industryArray;
    
    _selectRow = 0;
}

#pragma mark - 初始化TableView

- (void)initUpView
{
    _addClientView.acTableView.dataSource = self;
    _addClientView.acTableView.delegate = self;
    
    
    [_addClientView.commitBtn setTitle:@"添加到我的客户网点中" forState:UIControlStateNormal];
    [_addClientView.commitBtn setTitle:@" " forState:UIControlStateHighlighted];
    [_addClientView.commitBtn addTarget:self action:@selector(down:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)down:(UIBarButtonItem *)sender
{
    // 确认添加按钮
    NSLog(@"commit");
}


#pragma mark - tableView的代理方法

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44.0f;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    LXClientDetailTableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[LXClientDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        
    }
    // 标题
    cell.titleLabel.text = [_titleArray objectAtIndex:indexPath.row];
    cell.titleLabel.textColor = [UIColor blackColor];
    
    // 内容
    NSString *msg = @"苏果便利：";
    cell.msgField.text = msg;
    cell.msgField.textColor = [UIColor blackColor];
    CGSize sizeMsg = [cell.msgField.text sizeWithAFont:[UIFont systemFontOfSize:13]];
    [cell.msgField setFrame:CGRectMake(280-sizeMsg.width, 2, sizeMsg.width, 40)];
    cell.msgField.userInteractionEnabled = YES;
    if (indexPath.row == 1) {
        // 设置内容不可交互
        cell.msgField.userInteractionEnabled = NO;
        
        
        // 图标
        cell.industryImg.frame = CGRectMake(cell.msgField.frame.origin.x-40, 2, 40, 40);
        cell.industryImg.image = [UIImage imageNamed:_industryImgStr];
        
        // 箭头图标
        cell.armImg.image = [UIImage imageNamed:@"a.png"];
    }
    
    
    return cell;
    
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 1) {
        
        LXCustomActionSheet *lxCAS = [[LXCustomActionSheet alloc] initWithTitle:@"所属行业" withIconArray:_iArray withMsgArray:_industryArray withBtnTitle:nil withSelectArray:nil];
        lxCAS.delegate = self;
        [lxCAS showInView:_addClientView];
    } else {
        // 进入编辑界面
    
    
    }
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5;
}


#pragma mark - actionsheet的代理
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    // 按钮后处理在这
    LXCustomActionSheet *asheet = (LXCustomActionSheet *)actionSheet;
    if (buttonIndex >= 1 && buttonIndex <= asheet.messageArray.count) {
        NSString *str = [asheet.messageArray objectAtIndex:buttonIndex-1];
        NSLog(@"%@",str);
        _selectRow = buttonIndex-1;
        
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
